﻿using FangChanCrm.Services.Interface;
using FangChanCrmEF;
using Maticsoft.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

namespace FangChanCrm.Services.Realization
{
    public class t_RenYuanBiaoService : It_RenYuanBiaoService
    {
        public readonly MyContext _Context;
        public t_RenYuanBiaoService(MyContext myContext)
        {
            _Context = myContext;
        }

        public t_RenYuanBiao Add(t_RenYuanBiao t_RenYuanBiao)
        {
            _Context.t_RenYuanBiao.Add(t_RenYuanBiao);
            var test = _Context.SaveChanges();
            return _Context.t_RenYuanBiao.FirstOrDefault(x => x.BeiZhu1 == t_RenYuanBiao.BeiZhu1 && x.BeiZhu2 == t_RenYuanBiao.BeiZhu2 && x.BeiZhu3 == t_RenYuanBiao.BeiZhu3 && x.BeiZhu4 == t_RenYuanBiao.BeiZhu4 && x.BeiZhu5 == t_RenYuanBiao.BeiZhu5 && x.BeiZhu6 == t_RenYuanBiao.BeiZhu6 && x.BeiZhu7 == t_RenYuanBiao.BeiZhu7 && x.BeiZhu8 == t_RenYuanBiao.BeiZhu8 && x.BeiZhu9 == t_RenYuanBiao.BeiZhu9 && x.BeiZhu10 == t_RenYuanBiao.BeiZhu10 && x.XingMing == t_RenYuanBiao.XingMing && x.ZhangHao == t_RenYuanBiao.ZhangHao && x.MiMa == t_RenYuanBiao.MiMa && x.NianLing == t_RenYuanBiao.NianLing && x.XingBie == t_RenYuanBiao.XingBie && x.LianXiFangShi == t_RenYuanBiao.LianXiFangShi && x.GangWeiId == t_RenYuanBiao.GangWeiId && x.ZhuangTai == t_RenYuanBiao.ZhuangTai && x.XingJi == t_RenYuanBiao.XingJi && x.ZhanDuiId == t_RenYuanBiao.ZhanDuiId && x.HunYinZhuangKuang == t_RenYuanBiao.HunYinZhuangKuang && x.WeiXinHao == t_RenYuanBiao.WeiXinHao && x.YouXiang == t_RenYuanBiao.YouXiang && x.ShenFenZhengHao == t_RenYuanBiao.ShenFenZhengHao && x.JiaTingDiZhi == t_RenYuanBiao.JiaTingDiZhi && x.XueLi == t_RenYuanBiao.XueLi && x.RuZhiShiJian == t_RenYuanBiao.RuZhiShiJian && x.LiZhiShiJian == t_RenYuanBiao.LiZhiShiJian);
        }

        public bool Delete(int id)
        {
            _Context.t_RenYuanBiao.Remove(_Context.t_RenYuanBiao.Where(x => x.Id == id).ToList()[0]);
            return _Context.SaveChanges() > 0;
        }

        public t_RenYuanBiao GetById(int id)
        {
            return _Context.t_RenYuanBiao.Include(x => x.t_GangWeiBiao).Include(x => x.t_GangWeiBiao.t_BuMenBiao).Include(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao).Include(x => x.t_ZhanDuiBiao).FirstOrDefault(x => x.Id == id);
        }

        public List<t_RenYuanBiao> GetList()
        {
            return _Context.t_RenYuanBiao.Include(x => x.t_GangWeiBiao).Include(x => x.t_GangWeiBiao.t_BuMenBiao).Include(x => x.t_ZhanDuiBiao).Where(x => x.Id != 1).ToList();
        }

        public string GetListWithFenYe(t_RenYuanBiao t_RenYuanBiao, int start, int limit, string dir, int column)
        {
            var list = _Context.t_RenYuanBiao.Include(x => x.t_GangWeiBiao).Where(ReturnWhere(t_RenYuanBiao)).ToList();
            var listbumen = _Context.t_BuMenBiao.ToList();
            var listgongsi = _Context.t_GongSiBiao.ToList();
            for (int i = 0; i < list.Count; i++)
            {
                list[i].t_GangWeiBiao.t_RenYuanBiaos = null;
                if (list[i].t_ZhanDuiBiao == null)
                {
                    list[i].t_ZhanDuiBiao = new t_ZhanDuiBiao();
                }
                else
                {
                    list[i].t_ZhanDuiBiao.t_RenYuanBiaos = null;
                }
                list[i].t_GangWeiBiao.t_BuMenBiao = listbumen.Where(x => x.Id == list[i].t_GangWeiBiao.BuMenId).ToList()[0];
                list[i].t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao = listgongsi.Where(x => x.Id == list[i].t_GangWeiBiao.t_BuMenBiao.GongSiId).ToList()[0];
            }
            switch (column)
            {
                case 0:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.XingMing).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.XingMing).ToList();
                    }
                    break;
                case 1:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.NianLing).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.NianLing).ToList();
                    }
                    break;
                case 2:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.XingBie).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.XingBie).ToList();
                    }
                    break;
                case 3:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.LianXiFangShi).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.LianXiFangShi).ToList();
                    }
                    break;
                case 4:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.t_BuMenBiao.BuMenMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.t_BuMenBiao.BuMenMingCheng).ToList();
                    }
                    break;
                case 5:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.GangWeiMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.GangWeiMingCheng).ToList();
                    }
                    break;
                case 6:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.GongSiMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.GongSiMingCheng).ToList();
                    }
                    break;
                case 7:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.ShenFenZhengHao).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.ShenFenZhengHao).ToList();
                    }
                    break;
                default:
                    break;
            }
            return Helper.ListToJsonAddFenYe(list, start, limit);
        }
        public string GetListWithFenYeTestHyy(t_RenYuanBiao t_RenYuanBiao, int start, int limit, string dir, int column)
        {
            var list = _Context.t_RenYuanBiao.Include(x => x.t_GangWeiBiao).Where(ReturnWhere(t_RenYuanBiao)).ToList();
            var listbumen = _Context.t_BuMenBiao.ToList();
            var listgongsi = _Context.t_GongSiBiao.ToList();
            for (int i = 0; i < list.Count; i++)
            {
                list[i].t_GangWeiBiao.t_RenYuanBiaos = null;
                if (list[i].t_ZhanDuiBiao == null)
                {
                    list[i].t_ZhanDuiBiao = new t_ZhanDuiBiao();
                }
                else
                {
                    list[i].t_ZhanDuiBiao.t_RenYuanBiaos = null;
                }
                list[i].t_GangWeiBiao.t_BuMenBiao = listbumen.Where(x => x.Id == list[i].t_GangWeiBiao.BuMenId).ToList()[0];
                list[i].t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao = listgongsi.Where(x => x.Id == list[i].t_GangWeiBiao.t_BuMenBiao.GongSiId).ToList()[0];
            }
            #region 测试
            foreach (var item in list)
            {
                if (item.t_GangWeiBiao.GangWeiMingCheng == "")
                {

                }
            }
            #endregion
            switch (column)
            {
                case 0:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.XingMing).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.XingMing).ToList();
                    }
                    break;
                case 1:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.NianLing).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.NianLing).ToList();
                    }
                    break;
                case 2:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.XingBie).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.XingBie).ToList();
                    }
                    break;
                case 3:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.LianXiFangShi).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.LianXiFangShi).ToList();
                    }
                    break;
                case 4:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.t_BuMenBiao.BuMenMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.t_BuMenBiao.BuMenMingCheng).ToList();
                    }
                    break;
                case 5:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.GangWeiMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.GangWeiMingCheng).ToList();
                    }
                    break;
                case 6:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.GongSiMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.GongSiMingCheng).ToList();
                    }
                    break;
                case 7:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.ShenFenZhengHao).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.ShenFenZhengHao).ToList();
                    }
                    break;
                default:
                    break;
            }
            return Helper.ListToJsonAddFenYe(list, start, limit);
        }
        public string GetListWithFenYeYeJi(t_RenYuanBiao t_RenYuanBiao, int start, int limit, string dir, int column)
        {
            string tiaojian = "";
            if (!string.IsNullOrEmpty(t_RenYuanBiao.XingMing))
            {
                tiaojian += " and XingMing like '%" + t_RenYuanBiao.XingMing + "%'";
            }
            if (!string.IsNullOrEmpty(t_RenYuanBiao.ZhanQuId.ToString()) && t_RenYuanBiao.ZhanQuId != 0)
            {
                tiaojian += " and t_ZhanQuBiao.Id=" + t_RenYuanBiao.ZhanQuId + "";
            }
            if (!string.IsNullOrEmpty(t_RenYuanBiao.ZhanDuiId.ToString()) && t_RenYuanBiao.ZhanDuiId != 0)
            {
                tiaojian += " and t_ZhanDuiBiao.Id=" + t_RenYuanBiao.ZhanDuiId + "";
            }

            string tiaojianbaobei = "";
            string tiaojiandaikan = "";
            if (!string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu8) && !string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu9))
            {
                tiaojianbaobei = " and convert(datetime,beizhu1, 20) >='" + t_RenYuanBiao.BeiZhu8 + "' and convert(datetime,beizhu1, 20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
                tiaojiandaikan = " and convert(datetime,caozuoshijian,20) >='" + t_RenYuanBiao.BeiZhu8 + "' and convert(datetime,caozuoshijian,20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
            }
            if (!string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu8) && string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu9))
            {
                tiaojianbaobei = " and convert(datetime,beizhu1, 20) >='" + t_RenYuanBiao.BeiZhu8 + "'";
                tiaojiandaikan = " and convert(datetime,caozuoshijian,20) >='" + t_RenYuanBiao.BeiZhu8 + "'";
            }
            if (string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu8) && !string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu9))
            {
                tiaojianbaobei = " and convert(datetime,beizhu1, 20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
                tiaojiandaikan = " and convert(datetime,caozuoshijian,20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
            }


            string sql = "select XingMing,LianXiFangShi,zhanqumingcheng,zhanduimingcheng,(select count(*) from t_kehubiao where renyuanid=t_renyuanbiao.id " + tiaojianbaobei + ") as BaoBeiShu,(select count(*) from t_xiaoshouxiangxibiao where xiaoshoubiaoid in ( select id from t_xiaoshoubiao where kehuid in ( select id from t_kehubiao where renyuanid=t_renyuanbiao.id)) and xiaoshoudongzuo='确认到访' and ZhuangTai='确认到访' " + tiaojiandaikan + ") as daikanshu,(select count( distinct XiaoShouBiaoId) from t_xiaoshouxiangxibiao where xiaoshoubiaoid in ( select id from t_xiaoshoubiao where kehuid in ( select id from t_kehubiao where renyuanid=t_renyuanbiao.id)) and xiaoshoudongzuo='已认购' " + tiaojiandaikan + " ) as chengjiaoshu from t_renyuanbiao inner join t_zhanduibiao on t_renyuanbiao.zhanduiid=t_zhanduibiao.id inner join t_zhanqubiao on t_zhanduibiao.zhanquid=t_zhanqubiao.id where gangweiid=32 " + tiaojian + " order by chengjiaoshu desc";
            //List<t_RenYuanBiao> list = _Context.t_RenYuanBiao.FromSqlInterpolated(sql).ToList();
            var list1 = _Context.Database.SqlQuery<YeJi>(sql).ToList();



            #region MyRegion


            //var list = _Context.t_RenYuanBiao.Include(x => x.t_GangWeiBiao).Where(ReturnWhere(t_RenYuanBiao)).ToList();
            //var listbumen = _Context.t_BuMenBiao.ToList();
            //var listgongsi = _Context.t_GongSiBiao.ToList();
            //for (int i = 0; i < list.Count; i++)
            //{
            //    list[i].BeiZhu2 = BaoBeiShuLiang(Convert.ToInt32(list[i].Id));
            //    list[i].BeiZhu3 = DangFangShuLiang(Convert.ToInt32(list[i].Id));

            //    list[i].t_GangWeiBiao.t_RenYuanBiaos = null;
            //    if (list[i].t_ZhanDuiBiao == null)
            //    {
            //        list[i].t_ZhanDuiBiao = new t_ZhanDuiBiao();
            //    }
            //    else
            //    {
            //        list[i].t_ZhanDuiBiao.t_RenYuanBiaos = null;
            //    }
            //    list[i].t_GangWeiBiao.t_BuMenBiao = listbumen.Where(x => x.Id == list[i].t_GangWeiBiao.BuMenId).ToList()[0];
            //    list[i].t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao = listgongsi.Where(x => x.Id == list[i].t_GangWeiBiao.t_BuMenBiao.GongSiId).ToList()[0];
            //}
            switch (column)
            {
                case 0:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.XingMing).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.XingMing).ToList();
                    }
                    break;
                case 1:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.ZhanQuMingCheng).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.ZhanQuMingCheng).ToList();
                    }
                    break;
                case 2:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.ZhanDuiMingCheng).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.ZhanDuiMingCheng).ToList();
                    }
                    break;
                case 3:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.BaoBeiShu).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.BaoBeiShu).ToList();
                    }
                    break;
                case 4:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.DaiKanShu).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.DaiKanShu).ToList();
                    }
                    break;
                case 5:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.ChengJiaoShu).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.ChengJiaoShu).ToList();
                    }
                    break;

                default:
                    break;
            }
            #endregion
            return Helper.ListToJsonAddFenYe(list1, start, limit);
            //return "";
        }


        public string GetListWithFenYeYeJi1(t_RenYuanBiao t_RenYuanBiao, int start, int limit, string dir, int column)
        {
            string tiaojian = "";
            if (!string.IsNullOrEmpty(t_RenYuanBiao.XingMing))
            {
                tiaojian += " and XingMing like '%" + t_RenYuanBiao.XingMing + "%'";
            }
            if (!string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu10.ToString()) && t_RenYuanBiao.BeiZhu10 != "0")
            {
                tiaojian += " and t_BuMenBiao.Id=" + t_RenYuanBiao.BeiZhu10 + "";
            }

            string tiaojianbaobei = "";
            string tiaojiandaikan = "";
            if (!string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu8) && !string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu9))
            {
                tiaojianbaobei = " and convert(datetime,beizhu1, 20) >='" + t_RenYuanBiao.BeiZhu8 + "' and convert(datetime,beizhu1, 20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
                tiaojiandaikan = " and convert(datetime,caozuoshijian,20) >='" + t_RenYuanBiao.BeiZhu8 + "' and convert(datetime,caozuoshijian,20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
            }
            if (!string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu8) && string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu9))
            {
                tiaojianbaobei = " and convert(datetime,beizhu1, 20) >='" + t_RenYuanBiao.BeiZhu8 + "'";
                tiaojiandaikan = " and convert(datetime,caozuoshijian,20) >='" + t_RenYuanBiao.BeiZhu8 + "'";
            }
            if (string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu8) && !string.IsNullOrEmpty(t_RenYuanBiao.BeiZhu9))
            {
                tiaojianbaobei = " and convert(datetime,beizhu1, 20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
                tiaojiandaikan = " and convert(datetime,caozuoshijian,20) <='" + t_RenYuanBiao.BeiZhu9 + "'";
            }



            string sql = "select T_RenYuanBiao.Id,XingMing,LianXiFangShi,BuMenMingCheng,(select count(*) from t_kehubiao where renyuanid=t_renyuanbiao.id " + tiaojianbaobei + ") as BaoBeiShu,(select Count(distinct XiaoShouBiaoId) from t_xiaoshouxiangxibiao where  xiaoshoudongzuo='确认到访' and caozuoren=t_RenYuanBiao.Id and zhuangtai='确认到访' " + tiaojiandaikan + ") as daikanshu,(select count( distinct XiaoShouBiaoId) from t_xiaoshouxiangxibiao where xiaoshoubiaoid in ( select id from t_xiaoshoubiao where ZhiYeGuWenId = t_RenYuanBiao.Id ) and xiaoshoudongzuo='已认购' " + tiaojiandaikan + ") as chengjiaoshu from t_renyuanbiao inner join t_GangWeiBiao on t_renyuanbiao.GangWeiId=t_GangWeiBiao.id inner join t_BuMenBiao on t_GangWeiBiao.BuMenId=t_BuMenBiao.id where gangweiid=34 " + tiaojian + " order by chengjiaoshu desc";
            //List<t_RenYuanBiao> list = _Context.t_RenYuanBiao.FromSqlInterpolated(sql).ToList();
            var list1 = _Context.Database.SqlQuery<YeJi>(sql).ToList();

            switch (column)
            {
                case 0:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.XingMing).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.XingMing).ToList();
                    }
                    break;
                case 1:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.BuMenMingCheng).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.BuMenMingCheng).ToList();
                    }
                    break;
                case 2:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.BaoBeiShu).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.BaoBeiShu).ToList();
                    }
                    break;
                case 3:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.DaiKanShu).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.DaiKanShu).ToList();
                    }
                    break;
                case 4:
                    if (dir == "asc")
                    {
                        list1 = list1.OrderBy(x => x.ChengJiaoShu).ToList();
                    }
                    else
                    {
                        list1 = list1.OrderByDescending(x => x.ChengJiaoShu).ToList();
                    }
                    break;

                default:
                    break;
            }


            return Helper.ListToJsonAddFenYe(list1, start, limit);
            //return "";
        }




        public List<t_XiaoShouXiangXiBiao> ZongGetXiaoshouXinXiShuJu(int RenYuanId, string xiaoshoudongzuo, string zhuangtai)
        {
            List<t_XiaoShouXiangXiBiao> shuju = _Context.t_XiaoShouXiangXiBiao.Where(x => x.CaoZuoRen == RenYuanId || x.QueRenDaoFangRen == RenYuanId).ToList();
            if (zhuangtai != null && zhuangtai != "")
            {
                shuju = shuju.Where(x => x.ZhuangTai == zhuangtai).ToList();
            }
            if (xiaoshoudongzuo != null && xiaoshoudongzuo != "")
            {
                shuju = shuju.Where(x => x.XiaoShouDongZuo == xiaoshoudongzuo).ToList();
            }
            return shuju.DistinctBy(x => x.XiaoShouBiaoId).ToList();
        }
        public List<t_XiaoShouXiangXiBiao> GetXiaoshouXinXiShuJu(int RenYuanId, string kaishishijian, string jieshushijian, string xiaoshoudongzuo, string zhuangtai)
        {
            if (kaishishijian != null && kaishishijian != "" && jieshushijian != null && jieshushijian != "")
            {
                kaishishijian += " 0:00:00";
                jieshushijian += " 23:59:59";
                DateTime kaishi = Convert.ToDateTime(kaishishijian);
                DateTime jiezhi = Convert.ToDateTime(jieshushijian);
                List<t_XiaoShouXiangXiBiao> shuju = _Context.t_XiaoShouXiangXiBiao.Where(x => x.CaoZuoRen == RenYuanId || x.QueRenDaoFangRen == RenYuanId).ToList();
                if (zhuangtai != null && zhuangtai != "")
                {
                    shuju = shuju.Where(x => x.ZhuangTai == zhuangtai).ToList();
                }
                if (xiaoshoudongzuo != null && xiaoshoudongzuo != "")
                {
                    shuju = shuju.Where(x => x.XiaoShouDongZuo == xiaoshoudongzuo).ToList();
                }
                return shuju = shuju.Where(x => Convert.ToDateTime(x.CaoZuoShiJian) >= kaishi && Convert.ToDateTime(x.CaoZuoShiJian) <= jiezhi).DistinctBy(x => x.XiaoShouBiaoId).ToList();
            }
            else
            {
                int year = Convert.ToInt32(DateTime.Now.ToString("yyyy"));
                int month = Convert.ToInt32(DateTime.Now.ToString("MM"));
                int days = DateTime.DaysInMonth(year, month);
                DateTime t1 = new DateTime(year, month, days);
                DateTime t2 = new DateTime(year, month, 1);
                String jiezhishijian1 = t1.ToString("yyyy-MM-dd");
                jiezhishijian1 += " 23:59:59";
                DateTime kaishi = t2;
                DateTime jiezhi = Convert.ToDateTime(jiezhishijian1);
                List<t_XiaoShouXiangXiBiao> shuju = _Context.t_XiaoShouXiangXiBiao.Where(x => x.CaoZuoRen == RenYuanId || x.QueRenDaoFangRen == RenYuanId).ToList();
                if (zhuangtai != null && zhuangtai != "")
                {
                    shuju = shuju.Where(x => x.ZhuangTai == zhuangtai).ToList();
                }
                if (xiaoshoudongzuo != null && xiaoshoudongzuo != "")
                {
                    shuju = shuju.Where(x => x.XiaoShouDongZuo == xiaoshoudongzuo).ToList();
                }
                return shuju = shuju.Where(x => Convert.ToDateTime(x.CaoZuoShiJian) >= kaishi && Convert.ToDateTime(x.CaoZuoShiJian) <= jiezhi).DistinctBy(x => x.XiaoShouBiaoId).ToList();
            }
        }

        public string GetKeHuShuJu(string kaishishijian, string jieshushijian, int renyuanid, int start, int limit, string dir, int column)
        {
            if (kaishishijian != null && kaishishijian != "" && jieshushijian != null && jieshushijian != "")
            {
                kaishishijian += " 0:00:00";
                jieshushijian += " 23:59:59";
                DateTime kaishi = Convert.ToDateTime(kaishishijian);
                DateTime jiezhi = Convert.ToDateTime(jieshushijian);
                List<t_XiaoShouBiao> xiaoshobiao = new List<t_XiaoShouBiao>();
                List<int> shu = new List<int>();
                List<t_XiaoShouXiangXiBiao> shuju = _Context.t_XiaoShouXiangXiBiao.Where(x => x.CaoZuoRen == renyuanid || x.QueRenDaoFangRen == renyuanid).ToList();
                shuju = shuju.Where(x => Convert.ToDateTime(x.CaoZuoShiJian) >= kaishi && Convert.ToDateTime(x.CaoZuoShiJian) <= jiezhi).DistinctBy(x => x.XiaoShouBiaoId).ToList();
                for (int i = 0; i < shuju.Count; i++)
                {
                    if (i == 0)
                    {
                        shu.Add(shuju[i].XiaoShouBiaoId);
                    }
                    else
                    {
                        bool pd = true;
                        for (int p = 0; p < shu.Count; p++)
                        {
                            if (shu[p] == shuju[i].XiaoShouBiaoId)
                            {
                                pd = false;
                            }
                        }
                        if (pd)
                        {
                            shu.Add(shuju[i].XiaoShouBiaoId);
                        }
                    }
                }
                for (int u = 0; u < shu.Count; u++)
                {
                    int shuz = shu[u];
                    xiaoshobiao.Add(_Context.t_XiaoShouBiao.FirstOrDefault(x => x.Id == shuz));
                }
                var list = new List<t_KeHuBiao>();
                for (int j = 0; j < xiaoshobiao.Count; j++)
                {
                    list.Add(_Context.t_KeHuBiao.FirstOrDefault(x => x.Id == xiaoshobiao[j].KeHuId));
                }
                return Helper.ListToJsonAddFenYe(list, start, limit);
            }
            else
            {
                int year = Convert.ToInt32(DateTime.Now.ToString("yyyy"));
                int month = Convert.ToInt32(DateTime.Now.ToString("MM"));
                int days = DateTime.DaysInMonth(year, month);
                DateTime t1 = new DateTime(year, month, days);
                DateTime t2 = new DateTime(year, month, 1);
                String jiezhishijian1 = t1.ToString("yyyy-MM-dd");
                jiezhishijian1 += " 23:59:59";
                DateTime kaishi = t2;
                DateTime jiezhi = Convert.ToDateTime(jiezhishijian1);
                List<t_XiaoShouBiao> xiaoshobiao = new List<t_XiaoShouBiao>();
                List<int> shu = new List<int>();
                List<t_XiaoShouXiangXiBiao> shuju = _Context.t_XiaoShouXiangXiBiao.Where(x => x.CaoZuoRen == renyuanid || x.QueRenDaoFangRen == renyuanid).ToList();
                shuju = shuju.Where(x => Convert.ToDateTime(x.CaoZuoShiJian) >= kaishi && Convert.ToDateTime(x.CaoZuoShiJian) <= jiezhi).DistinctBy(x => x.XiaoShouBiaoId).ToList();

                for (int i = 0; i < shuju.Count; i++)
                {
                    if (i == 0)
                    {
                        shu.Add(shuju[i].XiaoShouBiaoId);
                    }
                    else
                    {
                        bool pd = true;
                        for (int p = 0; p < shu.Count; p++)
                        {
                            if (shu[p] == shuju[i].XiaoShouBiaoId)
                            {
                                pd = false;
                            }
                        }
                        if (pd)
                        {
                            shu.Add(shuju[i].XiaoShouBiaoId);
                        }
                    }
                }
                for (int u = 0; u < shu.Count; u++)
                {
                    int shuz = shu[u];
                    xiaoshobiao.Add(_Context.t_XiaoShouBiao.FirstOrDefault(x => x.Id == shuz));
                }
                var list = new List<t_KeHuBiao>();
                for (int j = 0; j < xiaoshobiao.Count; j++)
                {
                    list.Add(_Context.t_KeHuBiao.FirstOrDefault(x => x.Id == xiaoshobiao[j].KeHuId));
                }
                return Helper.ListToJsonAddFenYe(list, start, limit);
            }
        }
        public string ReturnWhere(t_RenYuanBiao t_RenYuanBiao)
        {
            string returnstr = "Id != 1";
            if (t_RenYuanBiao.BeiZhu1 != null)
            {
                returnstr = returnstr + " and BeiZhu1.Contains(\"" + t_RenYuanBiao.BeiZhu1 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu2 != null)
            {
                returnstr = returnstr + " and BeiZhu2.Contains(\"" + t_RenYuanBiao.BeiZhu2 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu3 != null)
            {
                returnstr = returnstr + " and BeiZhu3.Contains(\"" + t_RenYuanBiao.BeiZhu3 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu4 != null)
            {
                returnstr = returnstr + " and BeiZhu4.Contains(\"" + t_RenYuanBiao.BeiZhu4 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu5 != null)
            {
                returnstr = returnstr + " and BeiZhu5.Contains(\"" + t_RenYuanBiao.BeiZhu5 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu6 != null)
            {
                returnstr = returnstr + " and BeiZhu6.Contains(\"" + t_RenYuanBiao.BeiZhu6 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu7 != null)
            {
                returnstr = returnstr + " and BeiZhu7.Contains(\"" + t_RenYuanBiao.BeiZhu7 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu8 != null)
            {
                returnstr = returnstr + " and BeiZhu8.Contains(\"" + t_RenYuanBiao.BeiZhu8 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu9 != null)
            {
                returnstr = returnstr + " and BeiZhu9.Contains(\"" + t_RenYuanBiao.BeiZhu9 + "\")";
            }
            if (t_RenYuanBiao.BeiZhu10 != null)
            {
                returnstr = returnstr + " and BeiZhu10.Contains(\"" + t_RenYuanBiao.BeiZhu10 + "\")";
            }
            if (t_RenYuanBiao.XingMing != null)
            {
                returnstr = returnstr + " and XingMing.Contains(\"" + t_RenYuanBiao.XingMing + "\")";
            }
            if (t_RenYuanBiao.ZhangHao != null)
            {
                returnstr = returnstr + " and ZhangHao.Contains(\"" + t_RenYuanBiao.ZhangHao + "\")";
            }
            if (t_RenYuanBiao.MiMa != null)
            {
                returnstr = returnstr + " and MiMa.Contains(\"" + t_RenYuanBiao.MiMa + "\")";
            }
            if (t_RenYuanBiao.NianLing != null)
            {
                returnstr = returnstr + " and NianLing.Contains(\"" + t_RenYuanBiao.NianLing + "\")";
            }
            if (t_RenYuanBiao.XingBie != null)
            {
                returnstr = returnstr + " and XingBie.Contains(\"" + t_RenYuanBiao.XingBie + "\")";
            }
            if (t_RenYuanBiao.LianXiFangShi != null)
            {
                returnstr = returnstr + " and LianXiFangShi.Contains(\"" + t_RenYuanBiao.LianXiFangShi + "\")";
            }
            if (t_RenYuanBiao.GangWeiId > 0)
            {
                returnstr = returnstr + " and GangWeiId == " + t_RenYuanBiao.GangWeiId;
            }
            if (t_RenYuanBiao.ZhuangTai != null)
            {
                returnstr = returnstr + " and ZhuangTai.Contains(\"" + t_RenYuanBiao.ZhuangTai + "\")";
            }
            if (t_RenYuanBiao.XingJi != null)
            {
                returnstr = returnstr + " and XingJi.Contains(\"" + t_RenYuanBiao.XingJi + "\")";
            }
            if (t_RenYuanBiao.ZhanDuiId > 0)
            {
                returnstr = returnstr + " and ZhanDuiId == " + t_RenYuanBiao.ZhanDuiId;
            }
            if (t_RenYuanBiao.HunYinZhuangKuang != null)
            {
                returnstr = returnstr + " and HunYinZhuangKuang.Contains(\"" + t_RenYuanBiao.HunYinZhuangKuang + "\")";
            }
            if (t_RenYuanBiao.WeiXinHao != null)
            {
                returnstr = returnstr + " and WeiXinHao.Contains(\"" + t_RenYuanBiao.WeiXinHao + "\")";
            }
            if (t_RenYuanBiao.YouXiang != null)
            {
                returnstr = returnstr + " and YouXiang.Contains(\"" + t_RenYuanBiao.YouXiang + "\")";
            }
            if (t_RenYuanBiao.ShenFenZhengHao != null)
            {
                returnstr = returnstr + " and ShenFenZhengHao.Contains(\"" + t_RenYuanBiao.ShenFenZhengHao + "\")";
            }
            if (t_RenYuanBiao.JiaTingDiZhi != null)
            {
                returnstr = returnstr + " and JiaTingDiZhi.Contains(\"" + t_RenYuanBiao.JiaTingDiZhi + "\")";
            }
            if (t_RenYuanBiao.XueLi != null)
            {
                returnstr = returnstr + " and XueLi.Contains(\"" + t_RenYuanBiao.XueLi + "\")";
            }
            if (t_RenYuanBiao.RuZhiShiJian != null)
            {
                returnstr = returnstr + " and RuZhiShiJian.Contains(\"" + t_RenYuanBiao.RuZhiShiJian + "\")";
            }
            if (t_RenYuanBiao.LiZhiShiJian != null)
            {
                returnstr = returnstr + " and LiZhiShiJian.Contains(\"" + t_RenYuanBiao.LiZhiShiJian + "\")";
            }
            return returnstr;
        }
        public List<t_RenYuanBiao> GetGangWeiList(string gangweiid)
        {
            string[] shu = gangweiid.Split(",");
            string chaxue = "id != 1";
            for (int i = 0; i < shu.Length; i++)
            {
                if (i == 0)
                {
                    chaxue += " and GangWeiId = " + shu[i];
                }
                else
                {
                    chaxue += " or GangWeiId = " + shu[i];
                }
            }
            return _Context.t_RenYuanBiao.Where(chaxue).ToList();
        }

        public List<t_RenYuanBiao> GetXiaoShouShuJuList(string gangweiid, string zhanduiid, string zhanquid)
        {
            if (zhanduiid != null && zhanduiid != "")
            {
                string[] shu = gangweiid.Split(",");
                string chaxue = "id != 1";
                chaxue += " and ZhanDuiId = " + zhanduiid + " and ZhanQuId =" + zhanquid;
                chaxue += " and (";
                for (int i = 0; i < shu.Length; i++)
                {
                    if (i == 0)
                    {
                        chaxue += " GangWeiId = " + shu[i];
                    }
                    else
                    {
                        chaxue += " or GangWeiId = " + shu[i];
                    }
                }
                chaxue += ")";
                return _Context.t_RenYuanBiao.Where(chaxue).ToList();
            }
            else
            {
                string[] shu = gangweiid.Split(",");
                string chaxue = "id != 1";
                chaxue += " and ZhanQuId =" + zhanquid;
                chaxue += " and (";
                for (int i = 0; i < shu.Length; i++)
                {
                    if (i == 0)
                    {
                        chaxue += " GangWeiId = " + shu[i];
                    }
                    else
                    {
                        chaxue += " or GangWeiId = " + shu[i];
                    }
                }
                chaxue += ")";
                return _Context.t_RenYuanBiao.Where(chaxue).ToList();
            }
        }


        #region 业绩相关方法
        //获取报备数量
        public string BaoBeiShuLiang(int RenYuanId)
        {
            int year = System.DateTime.Now.Year;
            int month = System.DateTime.Now.Month;

            List<t_KeHuBiao> listkehu = _Context.t_KeHuBiao.Where(x => x.BeiZhu1.Contains("" + year + "/" + 07 + "") && x.RenYuanId == RenYuanId).ToList();
            return listkehu.Count.ToString();
        }
        //获取到访数量
        public string DangFangShuLiang(int RenYuanId)
        {



            //string count = "";
            //int kehushu = 0;
            //int querendaofangshu = 0;
            //获取当前登录人基本信息
            t_RenYuanBiao renyuan = GetById(RenYuanId);
            //获取所有职业顾问岗位
            List<t_GangWeiBiao> listgw = _Context.t_GangWeiBiao.Where(x => x.GangWeiMingCheng == "置业顾问").ToList();
            bool zhiye = false;
            for (int i = 0; i < listgw.Count; i++)
            {
                if (listgw[i].Id == renyuan.GangWeiId)
                {
                    zhiye = true;
                    break;
                }

            }
            if (zhiye == true)
            {
                FormattableString sql = $"select * from t_xiaoshouxiangxibiao where xiaoshoudongzuo='确认到访' and xiaoshoubiaoid in (select Id from t_xiaoshoubiao where ZhiYeGuWenId ={RenYuanId} ) ";
                List<t_XiaoShouXiangXiBiao> listxiaoshouxiangxi = _Context.t_XiaoShouXiangXiBiao.FromSqlInterpolated(sql).ToList();
                return listxiaoshouxiangxi.Count.ToString();
            }
            else
            {
                FormattableString sql = $"select * from t_XiaoShouXiangXiBiao where xiaoshoudongzuo='确认到访' and xiaoshoubiaoid in (select Id from t_KeHuBiao where RenYuanId = {RenYuanId}) ";
                List<t_XiaoShouXiangXiBiao> listxiaoshouxiangxi = _Context.t_XiaoShouXiangXiBiao.FromSqlInterpolated(sql).ToList();
                return listxiaoshouxiangxi.Count.ToString();
            }
        }

        public string GetListWithFenYe1(t_RenYuanBiao t_RenYuanBiao, int start, int limit, string dir, int column)
        {

            //string sql = "select t_RenYuanBiao.* from t_RenYuanBiao,t_GangWeiBiao,t_BuMenBiao,t_GongSiBiao,t_ZhanDuiBiao,t_ZhanQuBiao where t_RenYuanBiao.GangWeiId = t_GangWeiBiao.Id and t_GangWeiBiao.BuMenId = t_BuMenBiao.Id and t_BuMenBiao.GongSiId = t_GongSiBiao.Id and t_RenYuanBiao.ZhanDuiId = t_ZhanDuiBiao.id and t_ZhanDuiBiao.ZhanQuId = t_ZhanQuBiao.Id and t_RenYuanBiao.Id != '1'";
            //string sql = "t_RenYuanBiao.Id != 1";

            var list = _Context.t_RenYuanBiao.Include(x => x.t_GangWeiBiao).Include(x => x.t_GangWeiBiao.t_BuMenBiao).Include(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao).Include(x => x.t_ZhanDuiBiao).Include(x => x.t_ZhanDuiBiao.t_ZhanQuBiao).Where(x => x.Id != 1).ToList();

            if (t_RenYuanBiao.XingMing != null && t_RenYuanBiao.XingMing != "")
            {
                list = list.Where(x => x.XingMing.Contains(t_RenYuanBiao.XingMing)).ToList();
            }

            if (Convert.ToInt32(t_RenYuanBiao.BeiZhu9) != 0 && t_RenYuanBiao.BeiZhu9 != "")
            {
                list = list.Where(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.Id == Convert.ToInt32(t_RenYuanBiao.BeiZhu9)).ToList();
            }

            if (Convert.ToInt32(t_RenYuanBiao.BeiZhu10) != 0 && t_RenYuanBiao.BeiZhu10 != "")
            {
                list = list.Where(x => x.t_GangWeiBiao.t_BuMenBiao.Id == Convert.ToInt32(t_RenYuanBiao.BeiZhu10)).ToList();
            }

            if (t_RenYuanBiao.GangWeiId != 0 && t_RenYuanBiao.GangWeiId != null)
            {
                list = list.Where(x => x.GangWeiId == Convert.ToInt32(t_RenYuanBiao.GangWeiId)).ToList();
            }

            if (t_RenYuanBiao.ZhanQuId != 0 && t_RenYuanBiao.ZhanQuId != null)
            {
                list = list.Where(x => x.t_ZhanDuiBiao.t_ZhanQuBiao.Id == Convert.ToInt32(t_RenYuanBiao.ZhanQuId)).ToList();
            }

            if (t_RenYuanBiao.ZhanDuiId != 0 && t_RenYuanBiao.ZhanDuiId != null)
            {
                list = list.Where(x => x.ZhanDuiId == Convert.ToInt32(t_RenYuanBiao.ZhanDuiId)).ToList();
            }
            if (t_RenYuanBiao.ZhuangTai != null && t_RenYuanBiao.ZhuangTai != "")
            {
                list = list.Where(x => x.ZhuangTai==t_RenYuanBiao.ZhuangTai).ToList();
            }

            var listbumen = _Context.t_BuMenBiao.ToList();
            var listgongsi = _Context.t_GongSiBiao.ToList();
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].t_GangWeiBiao != null)
                {
                    list[i].t_GangWeiBiao.t_RenYuanBiaos = null;
                }
                if (list[i].t_ZhanDuiBiao == null)
                {
                    list[i].t_ZhanDuiBiao = new t_ZhanDuiBiao();
                }
                else
                {
                    list[i].t_ZhanDuiBiao.t_RenYuanBiaos = null;
                }
                list[i].t_ZhanQuBiao = new t_ZhanQuBiao();
                list[i].t_GangWeiBiao.t_BuMenBiao = listbumen.Where(x => x.Id == list[i].t_GangWeiBiao.BuMenId).ToList()[0];
                list[i].t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao = listgongsi.Where(x => x.Id == list[i].t_GangWeiBiao.t_BuMenBiao.GongSiId).ToList()[0];
                list[i].t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.t_BuMenBiaos = null;
                list[i].t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.t_RenYuanBiaos = null;
                list[i].t_GangWeiBiao.t_BuMenBiao.t_GangWeiBiaos = null;
                if (list[i].t_ZhanDuiBiao.t_ZhanQuBiao != null)
                {
                    list[i].t_ZhanDuiBiao.t_ZhanQuBiao.t_BuMenBiao = null;
                    list[i].t_ZhanDuiBiao.t_ZhanQuBiao.t_ZhanDuiBiaos = null;
                }
                list[i].t_GangWeiBiao.t_BuMenBiao.t_ZhanQuBiaos = null;
                list[i].t_ZhanQuBiao.t_ZhanDuiBiaos = null;

            }
            switch (column)
            {
                case 0:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.XingMing).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.XingMing).ToList();
                    }
                    break;
                case 1:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.NianLing).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.NianLing).ToList();
                    }
                    break;
                case 2:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.XingBie).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.XingBie).ToList();
                    }
                    break;
                case 3:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.LianXiFangShi).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.LianXiFangShi).ToList();
                    }
                    break;
                case 4:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.t_BuMenBiao.BuMenMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.t_BuMenBiao.BuMenMingCheng).ToList();
                    }
                    break;
                case 5:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.GangWeiMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.GangWeiMingCheng).ToList();
                    }
                    break;
                case 6:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.GongSiMingCheng).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.t_GangWeiBiao.t_BuMenBiao.t_GongSiBiao.GongSiMingCheng).ToList();
                    }
                    break;
                case 7:
                    if (dir == "asc")
                    {
                        list = list.OrderBy(x => x.ShenFenZhengHao).ToList();
                    }
                    else
                    {
                        list = list.OrderByDescending(x => x.ShenFenZhengHao).ToList();
                    }
                    break;
                default:
                    break;
            }
            return Helper.ListToJsonAddFenYe(list, start, limit);
        }

        public List<t_RenYuanBiao> GetZhanDuiRenYuanList(int zhanduiid)
        {
            return _Context.t_RenYuanBiao.Include(x => x.t_GangWeiBiao).Include(x => x.t_ZhanDuiBiao).Where(x => x.Id != 1 && x.ZhanDuiId == zhanduiid).ToList();
        }

        public List<t_ZhanDuiBiao> GetZhanQuZhanDuiList(int zhanquid)
        {
            return _Context.t_ZhanDuiBiao.Include(x => x.t_ZhanQuBiao).Where(x => x.id != 1 && x.ZhanQuId == zhanquid).ToList();
        }

        public List<t_GangWeiBiao> GetCKGangWei(int gongsiid)
        {
            return _Context.t_GangWeiBiao.Include(x => x.t_BuMenBiao).Include(x => x.t_BuMenBiao.t_GongSiBiao).Where(x => x.t_BuMenBiao.GongSiId == gongsiid).ToList();
        }


        //获取成交套数
        public int ChengJiaoTaoShu(int RenYuanId)
        {
            List<t_KeHuBiao> listkehu = _Context.t_KeHuBiao.Where(x => x.ZhuangTai == "已认购").ToList();
            List<t_XiaoShouBiao> listxiaoshou = _Context.t_XiaoShouBiao.Where(x => x.ZhiYeGuWenId == RenYuanId).ToList();
            return 1;
        }


        #endregion

    }

    public class YeJi
    {
        public int RenYuanId { get; set; }
        public string XingMing { get; set; }
        public string LianXiDianHua { get; set; }
        public string GongSiMingCheng { get; set; }
        public string BuMenMingCheng { get; set; }
        public string GangWeiMingCheng { get; set; }
        public string ZhanQuMingCheng { get; set; }
        public string ZhanDuiMingCheng { get; set; }
        public int BaoBeiShu { get; set; }
        public int DaiKanShu { get; set; }
        public int ChengJiaoShu { get; set; }
        public string ZhuanHuaBi { get; set; }
    }
}
